package com.finance.cooperate.feature.core.feature;

import java.util.HashSet;
import java.util.Set;

/**
 * @EnumName FeatureDefinition
 * @Description 特征名称定义
 * @Author shen
 * @Date 2022/5/25 16:32
 * @Modify ...
 */
public enum  FeatureDefinition {

    // ************************ PublicReader ************************
    f_public_uid("用户id", "f_public_uid", false, true),
    f_public_loan_num("贷款次数", "f_public_loan_num", false, true),


    // ************************ 是否存在源数据判断 *************************
    f_have_sms("是否存在短信", "f_have_sms", false, true),



    // ************************ SmsReader ************************
    f_sms_fasttext_01_score("fastText模型分", "f_sms_fasttext_01_score", false, true),
    f_sms_blistm_01_score("blistm模型分", "f_sms_blistm_01_score", false, true),
    f_sms_cnn_01_score("时间序列模型分", "f_sms_cnn_01_score", false, true),
    f_sms_words_("短信词统计", "f_sms_words_", true, false),
    f_sms_oppo_("短信发送方统计", "f_sms_oppo_", true, true),
    f_sms_loan_v1_("贷款短信统计", "f_sms_loan_v1_", false, true),
    f_sms_basic_v1_("基本信息统计", "f_sms_basic_v1_", false, true),


    // ************************ AppReader ************************
    f_app_count("APP 个数", "f_app_count", false, true),
    f_app_loan_top_10_count("用户贷款类app个数", "f_app_loan_top_10_count", false, true),
    f_app_loan_top_10_distance_submit_time_days_avg("用户贷款类app平均安装天数", "f_app_loan_top_10_distance_submit_time_days_avg", false, true),
    f_app_loan_top_10_distance_submit_time_days_max("用户贷款类app最大安装天数", "f_app_loan_top_10_distance_submit_time_days_max", false, true),
    f_app_loan_top_30_count("用户贷款类app个数", "f_app_loan_top_30_count", false, true),
    f_app_loan_top_30_distance_submit_time_days_avg("用户贷款类app平均安装天数", "f_app_loan_top_30_distance_submit_time_days_avg", false, true),
    f_app_loan_top_30_distance_submit_time_days_max("用户贷款类app最大安装天数", "f_app_loan_top_30_distance_submit_time_days_max", false, true),
    f_app_loan_top_60_count("用户贷款类app个数", "f_app_loan_top_60_count", false, true),
    f_app_loan_top_60_distance_submit_time_days_avg("用户贷款类app平均安装天数", "f_app_loan_top_60_distance_submit_time_days_avg", false, true),
    f_app_loan_top_60_distance_submit_time_days_max("用户贷款类app最大安装天数", "f_app_loan_top_60_distance_submit_time_days_max", false, true),
    f_app_nearly_1_months_app_count("近一个月app安装个数", "f_app_nearly_1_months_app_count", false, true),
    f_app_nearly_2_months_app_count("近两个月app安装个数", "f_app_nearly_2_months_app_count", false, true),
    f_app_nearly_3_months_app_count("近三个月app安装个数", "f_app_nearly_3_months_app_count", false, true),
    f_app_nearly_1_months_app_percentage("近一个月app安装占比", "f_app_nearly_1_months_app_percentage", false, true),
    f_app_nearly_2_months_app_percentage("近两个月app安装占比", "f_app_nearly_2_months_app_percentage", false, true),
    f_app_nearly_3_months_app_percentage("近三个月app安装占比", "f_app_nearly_3_months_app_percentage", false, true),
    f_app_first_app_install_days("最早安装的app距现在的天数", "f_app_first_app_install_days", false, true),
    f_app_last_app_install_days("最近安装的app距现在的天数", "f_app_last_app_install_days", false, true),
    f_app_has_chinese_count("app包含中文个数", "f_app_has_chinese_count", false, true),
    f_app_competition_level_v1("app 分层特征", "f_app_competition_level_v1", false, true),
    f_app_competition_level_1_count_v1("app 分层特征", "f_app_competition_level_1_count_v1", false, true),
    f_app_competition_level_2_count_v1("app 分层特征", "f_app_competition_level_2_count_v1", false, true),
    f_app_competition_level_3_count_v1("app 分层特征", "f_app_competition_level_3_count_v1", false, true),
    f_app_competition_level_4_count_v1("app 分层特征", "f_app_competition_level_4_count_v1", false, true),
    f_app_competition_level_5_count_v1("app 分层特征", "f_app_competition_level_5_count_v1", false, true),
    f_app_competition_level_v2("app 分层特征", "f_app_competition_level_v2", false, true),
    f_app_competition_level_1_count_v2("app 分层特征", "f_app_competition_level_1_count_v2", false, true),
    f_app_competition_level_2_count_v2("app 分层特征", "f_app_competition_level_2_count_v2", false, true),
    f_app_competition_level_3_count_v2("app 分层特征", "f_app_competition_level_3_count_v2", false, true),
    f_app_competition_level_4_count_v2("app 分层特征", "f_app_competition_level_4_count_v2", false, true),
    f_app_competition_level_5_count_v2("app 分层特征", "f_app_competition_level_5_count_v2", false, true),
    f_app_competition_level_3_to_5_count_v2("app 分层特征", "f_app_competition_level_3_to_5_count_v2", false, true),





    // ************************ ScrapyAppsReader ************************
    f_scrapy_apps_android_wear_count("爬虫各类app计数", "f_scrapy_apps_android_wear_count", false, true),
    f_scrapy_apps_art_design_count("爬虫各类app计数", "f_scrapy_apps_art_design_count", false, true),
    f_scrapy_apps_auto_vehicles_count("爬虫各类app计数", "f_scrapy_apps_auto_vehicles_count", false, true),
    f_scrapy_apps_beauty_count("爬虫各类app计数", "f_scrapy_apps_beauty_count", false, true),
    f_scrapy_apps_books_reference_count("爬虫各类app计数", "f_scrapy_apps_books_reference_count", false, true),
    f_scrapy_apps_business_count("爬虫各类app计数", "f_scrapy_apps_business_count", false, true),
    f_scrapy_apps_communication_count("爬虫各类app计数", "f_scrapy_apps_communication_count", false, true),
    f_scrapy_apps_comics_count("爬虫各类app计数", "f_scrapy_apps_comics_count", false, true),
    f_scrapy_apps_dating_count("爬虫各类app计数", "f_scrapy_apps_dating_count", false, true),
    f_scrapy_apps_education_count("爬虫各类app计数", "f_scrapy_apps_education_count", false, true),
    f_scrapy_apps_entertainment_count("爬虫各类app计数", "f_scrapy_apps_entertainment_count", false, true),
    f_scrapy_apps_events_count("爬虫各类app计数", "f_scrapy_apps_events_count", false, true),
    f_scrapy_apps_family_count("爬虫各类app计数", "f_scrapy_apps_family_count", false, true),
    f_scrapy_apps_finance_count("爬虫各类app计数", "f_scrapy_apps_finance_count", false, true),
    f_scrapy_apps_food_count("爬虫各类app计数", "f_scrapy_apps_food_count", false, true),
    f_scrapy_apps_games_count("爬虫各类app计数", "f_scrapy_apps_games_count", false, true),
    f_scrapy_apps_health_count("爬虫各类app计数", "f_scrapy_apps_health_count", false, true),
    f_scrapy_apps_house_count("爬虫各类app计数", "f_scrapy_apps_house_count", false, true),
    f_scrapy_apps_libraries_count("爬虫各类app计数", "f_scrapy_apps_libraries_count", false, true),
    f_scrapy_apps_lifestyle_count("爬虫各类app计数", "f_scrapy_apps_lifestyle_count", false, true),
    f_scrapy_apps_maps_count("爬虫各类app计数", "f_scrapy_apps_maps_count", false, true),
    f_scrapy_apps_medical_count("爬虫各类app计数", "f_scrapy_apps_medical_count", false, true),
    f_scrapy_apps_music_count("爬虫各类app计数", "f_scrapy_apps_music_count", false, true),
    f_scrapy_apps_news_count("爬虫各类app计数", "f_scrapy_apps_news_count", false, true),
    f_scrapy_apps_parenting_count("爬虫各类app计数", "f_scrapy_apps_parenting_count", false, true),
    f_scrapy_apps_personalization_count("爬虫各类app计数", "f_scrapy_apps_personalization_count", false, true),
    f_scrapy_apps_photography_count("爬虫各类app计数", "f_scrapy_apps_photography_count", false, true),
    f_scrapy_apps_productivity_count("爬虫各类app计数", "f_scrapy_apps_productivity_count", false, true),
    f_scrapy_apps_shopping_count("爬虫各类app计数", "f_scrapy_apps_shopping_count", false, true),
    f_scrapy_apps_social_count("爬虫各类app计数", "f_scrapy_apps_social_count", false, true),
    f_scrapy_apps_sports_count("爬虫各类app计数", "f_scrapy_apps_sports_count", false, true),
    f_scrapy_apps_tools_count("爬虫各类app计数", "f_scrapy_apps_tools_count", false, true),
    f_scrapy_apps_travel_count("爬虫各类app计数", "f_scrapy_apps_travel_count", false, true),
    f_scrapy_apps_video_editors_count("爬虫各类app计数", "f_scrapy_apps_video_editors_count", false, true),
    f_scrapy_apps_weather_count("爬虫各类app计数", "f_scrapy_apps_weather_count", false, true),
    f_scrapy_apps_top_overall_top_50("top N app 计数", "f_scrapy_apps_top_overall_top_50", false, true),
    f_scrapy_apps_top_new_top_50("top N app 计数", "f_scrapy_apps_top_new_top_50", false, true),
    f_scrapy_apps_top_apps_top_50("top N app 计数", "f_scrapy_apps_top_apps_top_50", false, true),
    f_scrapy_apps_finance_top_100("top N app 计数", "f_scrapy_apps_finance_top_100", false, true),
    f_scrapy_apps_finance_top_50("top N app 计数", "f_scrapy_apps_finance_top_50", false, true),
    f_scrapy_apps_finance_top_10("top N app 计数", "f_scrapy_apps_finance_top_10", false, true),

    f_scrapy_apps_finance_count_1w("爬虫各类app计数", "f_scrapy_apps_finance_count_1w", false, true),
    f_scrapy_apps_finance_rate("爬虫各类app计数", "f_scrapy_apps_finance_rate", false, true),
    f_scrapy_cnn_01_score("时间序列模型分", "f_scrapy_cnn_01_score", false, true),
    f_scrapy_apps_type_("爬虫app详细信息计数", "f_scrapy_apps_type_", false, true),


    // ************************ IdentityReader ************************
    f_identity_birthday_age("计算年龄", "f_identity_birthday_age", false, true),
    f_identity_gender("性别", "f_identity_gender", false, true),
    f_identity_loan_use("借款用途", "f_identity_loan_use", false, true),

    // ************************ UserReader ************************
    f_user_location_type("定位类型", "f_user_location_type", false, true),
    f_user_street_is_null("街道是否为空", "f_user_street_is_null", false, true),

    // ************************ PersonalReader ************************
    f_personal_marital_status("结婚状态", "f_personal_marital_status", false, true),
    f_personal_highest_school_record("最高学历", "f_personal_highest_school_record", false, true),
    f_personal_residential_detail_address_len("详细居住地址长度", "f_personal_residential_detail_address_len", false, true),
    f_personal_residential_type("居住类型", "f_personal_residential_type", false, true),

    // ************************ DeviceReader ************************
    f_device_brand_("设备品牌", "f_device_brand_", true, true),
    f_device_operator_("设备运营商", "f_device_operator_", true, true),
    f_device_time_zone_("设备时区", "f_device_time_zone_", true, true),
    f_device_country_("设备国家", "f_device_country_", true, true),
    f_device_network_("网络类型", "f_device_network_", true, true),
    f_device_mac_address_is_blank("mac地址是否为空", "f_device_mac_address_is_blank", false, true),
    f_device_cpu_num("CPU数量", "f_device_cpu_num", false, true),
    f_device_resolution_total("设备分辨率", "f_device_resolution_total", false, true),
    f_device_total_storage_size("手机总存储空间", "f_device_total_storage_size", false, true),
    f_device_can_use_storage_size("手机可用存储空间", "f_device_can_use_storage_size", false, true),
    f_device_total_memory_size("手机内存大小", "f_device_total_memory_size", false, true),
    f_device_sd_total_size("SD卡总存储空间", "f_device_sd_total_size", false, true),
    f_device_sd_can_use_size("SD卡可用存储空间", "f_device_sd_can_use_size", false, true),

    f_device_same_user_count("设备相同的用户数", "f_device_same_user_count", false, true),


    // ************************ BorrowingReader ************************
    f_borrowing_max_overdue_days("最大逾期天数", "f_borrowing_max_overdue_days", false, true),
    f_borrowing_min_overdue_days("最小逾期天数", "f_borrowing_min_overdue_days", false, true),
    f_borrowing_avg_overdue_days("平均逾期天数", "f_borrowing_avg_overdue_days", false, true),
    f_borrowing_avg_prepayment_hours("平均提前还款小时数", "f_borrowing_avg_prepayment_hours", false, true),
    f_borrowing_max_prepayment_hours("最大提前还款小时数", "f_borrowing_max_prepayment_hours", false, true),
    f_borrowing_min_prepayment_hours("最小提前还款小时数", "f_borrowing_min_prepayment_hours", false, true),
    f_borrowing_avg_loan_and_risk_interval_hours("平均通过风控和借贷小时数", "f_borrowing_avg_loan_and_risk_interval_hours", false, true),
    f_borrowing_last_loan_and_risk_interval_hours("最近一次通过风控和借贷小时数", "f_borrowing_last_loan_and_risk_interval_hours", false, true),
    f_borrowing_last_payoff_hour("上次还款小时数", "f_borrowing_last_payoff_hour", false, true),
    f_borrowing_same_ip_overdue_count("相同Ip的账单逾期个数", "f_borrowing_same_ip_overdue_count", false, false),

    // ************************ AppInstallDetailReader ************************
    f_app_install_detail_same_app_count("相同时间戳app个数", "f_app_install_detail_same_app_count", false, true),
    f_app_install_detail_same_uid("对方uid", "f_app_install_detail_same_uid", false, true),
    f_app_install_detail_same_device_id("对方设备id", "f_app_install_detail_same_device_id", false, true),
    f_app_install_detail_same_last_submit_time("对方进件时间", "f_app_install_detail_same_last_submit_time", false, true),
    f_app_install_detail_same_curr_device_id("当前设备id", "f_app_install_detail_same_curr_device_id", false, true),



    // ************************ CrcReader ************************
    f_crc_score("征信分", "f_crc_score", false, true),
    f_crc_consultas_("征信查询信息", "f_crc_consultas_", false, true),


    // ************************ IntermediateFeature ************************
    f_intermediate_feature_base_age_("计算年龄", "f_intermediate_feature_base_age_", true, true),
    f_intermediate_feature_base_marital_("婚姻状态", "f_intermediate_feature_base_marital_", true, true),
    f_intermediate_feature_base_gender_("性别", "f_intermediate_feature_base_gender_", true, true),


    f_intermediate_competition_("app竞品等级衍生特征", "f_intermediate_competition_", false, true),


    

    // ************************ sub model feature *************************
    f_app_retentive_time_("app留存时间", "f_app_retentive_time_", false, true),
    f_app_install_model_v1_("子模型特征", "f_app_install_model_v1_", true, true),
    f_app_time_model_v1_("子模型特征留存时间", "f_app_time_model_v1_", true, true),


    f_sms_model_v1_("子模型短信特征", "f_sms_model_v1_", true, true),


    f_model_sub_device_230815("设备子模型", "f_model_sub_device_230815", false, true),
    f_model_sub_install_230814("app子模型", "f_model_sub_install_230814", false, true),
    f_model_sub_time_230814("app子模型", "f_model_sub_time_230814", false, true),
    f_model_sub_scrapy_230816("app爬虫子模型", "f_model_sub_scrapy_230816", false, true),
    f_model_sub_sms_words_230812("短信关键词子模型", "f_model_sub_sms_words_230812", false, true),
    f_model_sub_sms_oppo_230913("短信发送方子模型", "f_model_sub_sms_oppo_230913", false, true),



    f_model_sub_device_231005("设备子模型", "f_model_sub_device_231005", false, false),

    f_model_sub_install_231005("app安装子模型", "f_model_sub_install_231005", false, false),

    f_model_sub_scrapy_231005("app爬虫子模型", "f_model_sub_scrapy_231005", false, false),

    f_model_sub_time_231005("app安装时间子模型", "f_model_sub_time_231005", false, false),

    f_model_sub_sms_231006("短信子模型", "f_model_sub_sms_231006", false, false),



    f_model_v1_230817("综合模型", "f_model_v1_230817", false, true),
    f_model_v2_230914("综合模型", "f_model_v2_230914", false, true),


    f_model_v3_230928("综合模型", "f_model_v3_230928", false, true),

    f_model_v4_231007("综合模型", "f_model_v4_231007", false, true),



    NULL("", "", false, false);

    private String desc;
    private String value;
    private boolean isOneHot;
    private boolean status;

    FeatureDefinition(String desc, String value, boolean isOneHot, boolean status) {
        this.desc = desc;
        this.value = value;
        this.isOneHot = isOneHot;
        this.status = status;
    }

    public String getValue() {
        return this.value;
    }

    public String getDesc() {
        return this.desc;
    }

    public boolean getIsOneHot() {
        return this.isOneHot;
    }

    public boolean getStatus() {
        return this.status;
    }

    public static boolean getStatus(String value) {
        FeatureDefinition[] featureDefinitions = values();
        for (FeatureDefinition featureDefinition : featureDefinitions) {
            if (featureDefinition.getValue().equals(value)) {
                return featureDefinition.getStatus();
            }
        }
        return false;
    }

    public static String getDesc(String value) {
        FeatureDefinition[] featureDefinitions = values();
        for (FeatureDefinition featureDefinition : featureDefinitions) {
            if (featureDefinition.getValue().equals(value)) {
                return featureDefinition.getDesc();
            }
        }
        return null;
    }


    public static Boolean contains(String value){
        for(FeatureDefinition featureDefinition : FeatureDefinition.values()){
            if(featureDefinition.getValue().equals(value)){
                return true;
            }
        }
        return false;
    }


    public static boolean isOneHot(String value) {

        if (!contains(value) || value.endsWith("_")) {
            // 可能是热编码子类型

            FeatureDefinition[] featureDefinitions = values();
            for (FeatureDefinition featureDefinition : featureDefinitions) {

                // 之前判断不对，如果后面有多个"__"就不对了

                String v = featureDefinition.getValue();
                if (v.endsWith("_")) {

                    if (value.length() >= v.length()) {

                        String valueTemp = value.substring(0, v.length());

                        if (v.equals(valueTemp)) {
                            return featureDefinition.getIsOneHot();
                        }

                    }

                }

            }

        }

        return false;
    }




    public static void main(String[] args){

        // 输出特征列表
        outputFeatureList();

        // 输出特征数量
//        outputFeatureNum();

    }


    /**
     * @Author shen
     * @Description 启用特征和关闭特征数量
     * @Date 22:40 2022/11/25
     * @Param []
     * @return void
     **/
    private static void outputFeatureNum() {

        int length = FeatureDefinition.values().length;

        Set<String> set = new HashSet<>();
        for (FeatureDefinition e : FeatureDefinition.values()) {

            if (e.getStatus()) {
                set.add(e.getValue());
            }
        }


        System.out.println("总特征数量：" + length);
        System.out.println("启用特征数量：" + set.size());

    }

    /**
     * @Author shen
     * @Description 特征列表
     * @Date 22:39 2022/11/25
     * @Param []
     * @return void
     **/
    private static void outputFeatureList() {
        for (FeatureDefinition e : FeatureDefinition.values()) {

            if (e.getStatus()) {
                System.out.println(e.getValue() + "： " + e.getDesc());
            }

        }
    }






}
